using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;

namespace TMS.Application.Common.Interface
{
    public interface IRepository<T>
    {
        /// <summary>
        /// 用于查询的“表”
        /// </summary>
        /// <value></value>
        IQueryable<T> Table { get; }

        /// <summary>
        /// 根据id获取实体
        /// </summary>
        /// <param name="id">实体的主键id</param>
        /// <returns>实体</returns>
        Task<T?> GetByIdAsync(Guid id);

        /// <summary>
        /// 插入一个实体到数据库
        /// </summary>
        /// <param name="entity">实体</param>
        /// <returns>（插入后的）实体</returns>
        Task<T> AddAsync(T entity);

        /// <summary>
        /// 批量插入实体到数据库
        /// </summary>
        /// <param name="entities">若干个实体</param>
        /// <returns>（插入后的）若干个实体</returns>
        Task<IEnumerable<T>> AddBulkAsync(IEnumerable<T> entities);

        /// <summary>
        /// 更新实体到数据库
        /// </summary>
        /// <param name="entity">实体</param>
        /// <returns>（更新后的）实体</returns>
        Task<T> UpdateAsync(T entity);

        /// <summary>
        /// 批量更新实体到数据库
        /// </summary>
        /// <param name="entities">若干实体</param>
        /// <returns>（更新后的）若干实体</returns>
        Task<IEnumerable<T>> UpdateBulkAsync(IEnumerable<T> entities);

        /// <summary>
        /// 根据id删除一条记录，默认伪删除，如果shouldHardDel为true，则真正删除一条
        /// </summary>
        /// <param name="id">主键id</param>
        /// <param name="shouldHardDel">是否真正删除</param>
        /// <returns>没有返回值</returns>
        Task DeleteAsync(Guid id, bool shouldHardDel = false);

        /// <summary>
        /// 根据实体删除一条记录，默认伪删除，如果shouldHardDel为true，则真正删除一条
        /// </summary>
        /// <param name="entity">实体</param>
        /// <param name="shouldHardDel">是否真正删除</param>
        /// <returns>没有返回值</returns>
        Task DeleteAsync(T entity, bool shouldHardDel = false);

        /// <summary>
        /// 批量删除若干实体，默认伪删除，如果shouldHardDel为true，则真正删除若干条
        /// </summary>
        /// <param name="entities">若干实体</param>
        /// <param name="shouldHardDel">是否真正删除</param>
        /// <returns>无返回值</returns>
        Task DeleteBulkAsync(IEnumerable<T> entities, bool shouldHardDel = false);

        void Delete(Guid id);
    }
}